package com.dengyiming.item.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dengyiming.item.constants.MqConstants;
import com.dengyiming.item.mapper.ItemMapper;
import com.dengyiming.item.pojo.Item;
import com.dengyiming.item.service.IItemService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private IItemService itemService;

    @Override
    public void itemStatus(Long id, Integer status) {
        Item item = new Item();
        item.setId(id);
        item.setStatus(status);
        itemService.updateById(item);

        String key = item.getStatus() == 1 ? MqConstants.ITEM_INSERT_KEY : MqConstants.ITEM_DELETE_KEY;
        rabbitTemplate.convertAndSend(MqConstants.ITEM_EXCHANGE, key, item.getId());
    }
}
